//
//  MaterView.m
//  FoodFamily
//
//  Created by dlios on 15-6-20.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "MaterView.h"

@implementation MaterView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame
{
    [super initWithFrame:frame];
    if (self) {
        
        
        [self mater];
        
            }

    return self;
}
-(void)mater
{
    self.scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.scrollView.pagingEnabled = YES;//按页翻
    self.scrollView.bounces = NO;//禁止边界反弹效果
    self.scrollView.showsHorizontalScrollIndicator = YES;//隐藏横向水平滑动条
    self.scrollView.showsVerticalScrollIndicator = NO;//隐藏纵向滑动条
    self.scrollView.backgroundColor = [UIColor clearColor];
    //返回顶部
    self.scrollView.scrollsToTop = YES;
    [self addSubview:self.scrollView];
    
    
    
    UIImageView *imagev = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    imagev.image = [UIImage imageNamed:@"beijing.png"];
    [self.scrollView addSubview:imagev];
    //rootBtn.frame = CGRectMake(10, 0+45*i, self.view.frame.size.width, 45);
   
    UIImageView *imageview  = [[UIImageView alloc]initWithFrame:CGRectMake(190*COEFFICIENTW, 5, 180*COEFFICIENTW, 180)];
    imageview.image = [UIImage imageNamed:@"cailiaobeijing.png"];
    [self.scrollView addSubview:imageview];
#pragma 背景

    
    
    self.myimageview = [[UIImageView alloc]initWithFrame:CGRectMake(200*COEFFICIENTW, 15, 160*COEFFICIENTH, 160)];
    self.myimageview.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:self.myimageview];
    
    self.namelabel = [[UILabel alloc]initWithFrame:CGRectMake(5*COEFFICIENTW, 0, 150*COEFFICIENTH, 40)];
    self.namelabel.backgroundColor = [UIColor clearColor];
    [self.namelabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
    self.namelabel.textColor = [UIColor brownColor];
    [self.scrollView addSubview:self.namelabel];
    
    
    self.englishNamelabel = [[UILabel alloc]initWithFrame:CGRectMake(5*COEFFICIENTW, 20, 190*COEFFICIENTH, 40)];
    self.englishNamelabel.backgroundColor = [UIColor clearColor];
    self.englishNamelabel.textColor = [UIColor brownColor];
//    self.englishNamelabel.font = [UIFont systemFontOfSize:10];
    [self.englishNamelabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
    [self.scrollView addSubview:self.englishNamelabel];
#pragma  原料
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5*COEFFICIENTW, 40, 50*COEFFICIENTH, 50)];
    label.backgroundColor = [UIColor clearColor];
    label.text = @"原料:";
    [label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
    label.textColor = [UIColor brownColor];
    [self.scrollView addSubview:label];
    //NSLog(@"%@",NSStringFromCGRect(label.frame));
    self.fittingRestrictionlabel = [[UILabel alloc]initWithFrame:CGRectMake(label.frame.origin.x + label.frame.size.width, _englishNamelabel.frame.origin.y + _englishNamelabel.frame.size.height - 10, imageview.frame.origin.x - label.frame.origin.x - label.frame.size.width, 90)];
   // NSLog(@"77777%@",NSStringFromCGRect(_fittingRestrictionlabel.frame));
    self.fittingRestrictionlabel.backgroundColor = [UIColor clearColor];
    self.fittingRestrictionlabel.font = [UIFont systemFontOfSize:13];
    [self heightFor:self.fittingRestrictionlabel.text];
    self.fittingRestrictionlabel.numberOfLines = 0;//换行
 

    
    [self.scrollView addSubview:self.fittingRestrictionlabel];
#pragma 调料
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(5*COEFFICIENTW, 130, 50*COEFFICIENTH, 50)];
    label1.text = @"调料:";
    [label1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];

    label1.textColor = [UIColor brownColor];
    label1.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:label1];
    self.methodLabel = [[UILabel alloc]initWithFrame:CGRectMake(60*COEFFICIENTW, 130, 132*COEFFICIENTH, 70)];
    self.methodLabel.backgroundColor = [UIColor clearColor];
    self.methodLabel.textColor = [UIColor blackColor];
    self.methodLabel.font = [UIFont systemFontOfSize:13];
    self.methodLabel.numberOfLines = 0;
    [self heightFor:self.methodLabel.text];
    [self.scrollView addSubview:self.methodLabel];
#pragma 图片 盐
//    self.imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(220, 190, 150, 130)];
//    self.imageview1.backgroundColor = [UIColor redColor];
//    [self addSubview:self.imageview1];
   
   

   }
-(void)setMovie:(Movie *)movie
{
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    
    self.namelabel.text = movie.name;
   
    self.englishNamelabel.text = movie.englishName;
    self.fittingRestrictionlabel.text = movie.fittingRestriction;
    self.methodLabel.text = movie.method;
//    NSURL *urlstring  = [NSURL URLWithString:self.movie.imagePathLandscape];
//    [self.imagePath sd_setImageWithURL:urlstring];
   }
-(void)setMat:(Mater *)mat
{
    if (_mat != mat) {
        [_mat release];
        _mat = [mat retain];
    }
    
    NSURL *url = [NSURL URLWithString:mat.imagePath];
    [self.myimageview sd_setImageWithURL:url];
   
    
    
}

-(void)setTblSeasoningarray:(NSMutableArray *)TblSeasoningarray
{
    if (_TblSeasoningarray != TblSeasoningarray) {
        [_TblSeasoningarray release];
        _TblSeasoningarray = [TblSeasoningarray retain];
    }

   
    for (int i = 0; i <TblSeasoningarray.count; i++) {
        Mater *mater = [[Mater alloc]init];
        mater = [TblSeasoningarray objectAtIndex:i];

            UIImageView *imageV = [[[UIImageView alloc] init]autorelease];
            imageV.backgroundColor = [UIColor clearColor];
            [self.scrollView addSubview:imageV];
            imageV.frame =CGRectMake((20 + i % 3 * (100 + 30))*COEFFICIENTW, (210 + i / 3 * (80 + 30)), 80*COEFFICIENTH, 80*COEFFICIENTH);
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, 80*COEFFICIENTH, 20)];
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor brownColor];
        label.text = mater.materialName;
        [label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:19]];
        [imageV addSubview:label];
            NSURL *url = [NSURL URLWithString:mater.imagePath];
                    [imageV sd_setImageWithURL:url];

    }
    self.scrollView.contentSize = CGSizeMake(0, TblSeasoningarray.count/3 *100  + (TblSeasoningarray.count / 3 ) * 20 + 290);
}




-(CGFloat)heightFor:(NSString *)content
{
    CGSize size = CGSizeMake(  135, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15.0] forKey:NSFontAttributeName];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
    
}@end
